package application;

import java.util.List;

public class ATM {
	private static Session session;
	private static CashDispenser cashDispenser = new CashDispenser();
	private static CardReader cardreader=new CardReaderImpl();
	private static Bank bank= new Bank();;
	private static Receipt receipt;

	//插卡
	public void plugin(String cardID){
		cardreader.readCard(cardID);
	}
	//验证
	public static Account active(String cardId, String passwd){
		Account a=bank.validate(cardId, passwd);
		if(a!=null) {
			session = Session.getSession(a);
		} else {
			System.out.println("werr");
		}
		System.out.println("sssssssssssss");
		return a;
	}
	//取款
	public static void askForTransaction(int amount) {
        Withdraw withdraw=null;
        try {
            withdraw= session.createWithdrawSession();
        }catch(Exception e){
	        System.out.println(e.getMessage());
        }
		withdraw.withdraw(amount);
        session.getWithdraws().get(0).setAmount(withdraw.getAmount());
		cashDispenser.spitOutMoney(amount);

	}
	public static List<Withdraw> askForPrintReceipt() {
		receipt=new Receipt(session.getWithdraws());
		return session.getWithdraws();
	}
	public static void exit() {
		session.closeSession();
		cardreader.exitCard();
	}
}
